<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:p="http://primefaces.prime.com.tr/ui">
		<div align="left">
		<h:form id="idPessoaMBForm">
			<p:panel>
				<p:messages globalOnly="true" rendered="true"/>
				<f:facet name="header">
					<h:outputText value="#{msg.usuarioTitulo}" />
				</f:facet>
				<fieldset id="legend_area"> <legend id="legend"><h:outputLabel	value="#{msg.usuarioDados}" /></legend> 
				
				<h:panelGrid columns="4">
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.nome}" for="idNomePes"/><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idNomePes" styleClass="mensagem_erro_campo" /><br/>
						<h:inputText id="idNomePes" value="#{pessoaMB.pessoa.nome}" size="50" onkeyup="javascript:toUpperCase(this);" 
						 required="true" requiredMessage="#{msg.campoObrigatorio}">
						 	<h:inputHidden value="#{pessoaMB.pessoa.id}"/>
							<rich:ajaxValidator event="onblur" />
						</h:inputText>
					</h:panelGroup>
					
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.sexo}" for="idSexoPes"/><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idSexoPes" styleClass="mensagem_erro_campo"/><br/>
						<rich:comboBox id="idSexoPes" value="#{pessoaMB.pessoa.sexo}" defaultLabel="#{msg.escolhaOpcao}" enableManualInput="false" 
									   required="true" requiredMessage="#{msg.campoObrigatorio}" converter="sexoConverter">
							<f:selectItems value="#{pessoaMB.sexoListOpts}"/>
							<rich:ajaxValidator event="onblur" />
	           			</rich:comboBox>
           			</h:panelGroup>

					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.funcao}" for="idFuncaoPes" /><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idFuncaoPes" styleClass="mensagem_erro_campo"/><br/>
						<rich:comboBox id="idFuncaoPes" defaultLabel="#{msg.escolhaOpcao}" width="250" enableManualInput="false"
						 	value="#{pessoaMB.pessoa.funcao.nome}" required="true" requiredMessage="#{msg.campoObrigatorio}" >
							<f:selectItems value="#{funcaoMB.funcaoOpts}" />
							<rich:ajaxValidator event="onblur" />
						</rich:comboBox>
					</h:panelGroup>
					
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.setor}" for="idSetorPes" /><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idSetorPes" styleClass="mensagem_erro_campo"/>
						<rich:comboBox id="idSetorPes" defaultLabel="#{msg.escolhaOpcao}" width="250"
						 	value="#{pessoaMB.pessoa.setor.nome}" required="true" requiredMessage="#{msg.campoObrigatorio}" >
							<f:selectItems value="#{setorMB.setorOpts}" />
							<rich:ajaxValidator event="onblur" />
						</rich:comboBox>
					</h:panelGroup>
				</h:panelGrid>
				<br />
				
				<h:outputFormat value="#{msg.contato}" styleClass="label_bold"/>
				<h:panelGrid columns="4"> 
					<h:panelGroup style="width: 400px;">
						<br/>
						<h:outputLabel value="#{msg.telefoneEmp}" for="idContatoPesEmp" /><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idContatoPesEmp" styleClass="mensagem_erro_campo"/><br/>
						<p:inputMask id="idContatoPesEmp" mask="(99)9999-9999" value="#{pessoaMB.contato.numeroEmpresa}" 
							required="true" requiredMessage="#{msg.campoObrigatorio}" size="16">
						</p:inputMask>
						<h:inputHidden value="#{pessoaMB.contato.id}"/>
					</h:panelGroup>

					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.ramal}" for="idContatoPesRamal" />
					</h:panelGroup>
					<h:panelGroup>
						<br/>
						<p:inputMask id="idContatoPesRamal" mask="9999" value="#{pessoaMB.contato.ramal}" size="6">
						</p:inputMask>
					</h:panelGroup>
					
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.telefoneCel}" for="idContatoPesCel" />
					</h:panelGroup>
					<h:panelGroup>
						<br/>
						<p:inputMask id="idContatoPesCel" mask="(99)9999-9999" value="#{pessoaMB.contato.numeroCelular}" size="16">
						</p:inputMask>
					</h:panelGroup>

					<h:panelGroup>
					<br/>	
					<h:outputLabel value="#{msg.email}" for="idEmailPes" /><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
					<rich:message for="idEmailPes" styleClass="mensagem_erro_campo"/><br/>
					<h:inputText id="idEmailPes" value="#{pessoaMB.pessoa.email}" required="true" requiredMessage="#{msg.campoObrigatorio}" maxlength="45" size="45">
						<f:validator validatorId="checkemailinvalido" />
						<rich:ajaxValidator event="onblur" />
					</h:inputText>
					</h:panelGroup>				
				</h:panelGrid>
				<br />
				</fieldset><br />
				
				<fieldset id="legend_area"> <legend id="legend"><h:outputLabel value="#{msg.usuarioDadosConfiguracao}" /></legend> 
					<h:panelGrid columns="3" cellspacing="2">
						<h:panelGroup>
							<h:outputLabel value="#{msg.perfil}" for="idPerfilUsuario" /><span class="req"> *</span>
							<h:inputHidden value="#{pessoaMB.roleNames.id}"/>
						</h:panelGroup>
						<rich:comboBox id="idPerfilUsuario" defaultLabel="#{msg.escolhaOpcao}" width="250" enableManualInput="false"
						 	value="#{pessoaMB.roleNames.description}" required="true" requiredMessage="#{msg.campoObrigatorio}" >
							<f:selectItems value="#{roleNamesMB.roleOpts}" />
							<rich:ajaxValidator event="onblur" />
						</rich:comboBox><rich:message for="idPerfilUsuario" styleClass="mensagem_erro_campo"/>
						<h:outputLabel value="#{msg.contaAtivada}" for="idContaAtivada" />
						<h:selectOneRadio id="idContaAtivada" value="#{pessoaMB.user.accountEnabled}">
							<f:selectItem itemLabel="#{msg.sim}" itemValue="true"/>
							<f:selectItem itemLabel="#{msg.nao}" itemValue="false"/>
						</h:selectOneRadio><rich:message for="idContaAtivada" styleClass="mensagem_erro_campo"/>

						<h:outputLabel value="#{msg.acessoLogin}" for="idLoginPes" />
						<h:inputText id="idLoginPes" value="#{pessoaMB.user.userName}" >
						<h:inputHidden value="#{pessoaMB.user.id}"/>
						</h:inputText>  <h:panelGroup></h:panelGroup>	
					</h:panelGrid>
				</fieldset><br/>
				
				<h:panelGrid columns="2" width="100%" style="text-align:center;">
					<h:panelGroup>
						<a4j:commandButton value="#{msg.botaoSalvar}" 
							action="#{pessoaMB.save}" reRender="idPessoaMBForm, pessoaList" style="text-align:center;"/>
						<rich:spacer width="15px"/>
						<a4j:commandButton value="#{msg.botaoAtualizar}" action="#{pessoaMB.atualiza}" style="text-align:center;"
							reRender="idPessoaMBForm, pessoaList"/>
						<rich:spacer width="15px"/>
						<a4j:commandButton value="#{msg.botaoLimpar}" action="#{pessoaMB.limpar}" style="text-align:center;" 
							reRender="idPessoaMBForm"/>
					</h:panelGroup>
				</h:panelGrid>
			</p:panel>
		</h:form><br />
		<h:form>
			<p:panel>
				<a4j:commandButton reRender="idPessoaMBForm" value="#{msg.alterar}" action="#{pessoaMB.listaToFormPessoa}"/>
				<h:commandButton onclick="return confirm('Deseja excluir o registro?')" value="#{msg.excluir}" action="#{pessoaMB.remove}" reRender="pessoaList"/>
				
				<p:dataTable id="pessoaList" var="pessoa" value="#{pessoaMB.pessoaList}" paginator="true" rows="6" 
					selection="#{pessoaMB.pessoaSelectedList}" selectionMode="multiple">
					<p:column filterBy="#{pessoa.nome}" sortBy="#{pessoa.nome}" width="300">
						<f:facet name="header">
							<h:outputText value="#{msg.nome}" />
						</f:facet>
						<h:outputText value="#{pessoa.nome}" />
					</p:column>
				
					<p:column sortBy="#{pessoa.users.userName}">
						<f:facet name="header">
							<h:outputText value="#{msg.acessoLogin}" />
						</f:facet>
						<h:outputText value="#{pessoa.users.userName}"/>
					</p:column>
					
					<p:column filterBy="#{pessoa.users.roleNamesList[0].description}" sortBy="#{pessoa.users.roleNamesList[0].description}">
						<f:facet name="header">
							<h:outputText value="#{msg.perfil}" />
						</f:facet>
						<h:outputText value="#{pessoa.users.roleNamesList[0].description}"/>
					</p:column>
					
					<p:column filterBy="#{pessoa.setor.nome}" sortBy="#{pessoa.setor.nome}">
						<f:facet name="header">
							<h:outputText value="#{msg.setor}" />
						</f:facet>
						<h:outputText value="#{pessoa.setor.nome}"/>
					</p:column>			

					<p:column sortBy="#{pessoa.funcao.nome}">
						<f:facet name="header">
							<h:outputText value="#{msg.funcao}" />
						</f:facet>
						<h:outputText value="#{pessoa.funcao.nome}"/>
					</p:column>	
						
					<p:column sortBy="#{pessoa.contato.numeroEmpresa}" width="80">
						<f:facet name="header">
							<h:outputText value="#{msg.telefoneEmp}" />
						</f:facet>
						<h:outputText value="#{pessoa.contato.numeroEmpresa}"/>
					</p:column>								

					<p:column>
						<f:facet name="header">
							<h:outputText value="#{msg.ramal}" />
						</f:facet>
						<h:outputText value="#{pessoa.contato.ramal}"/>
					</p:column>	
				</p:dataTable>
				<h:outputText value="#{msg.exportarTodosDados}" style="font-weight:bold"/>:
				<h:commandLink>
					<p:graphicImage value="/images/excel.png" style="border:0;"/>
					<p:dataExporter type="xls" target="pessoaList" fileName="#{msg.pessoa}" />
				</h:commandLink>
				<h:commandLink>
					<p:graphicImage value="/images/pdf.png" style="border:0;"/>
					<p:dataExporter type="pdf" target="pessoaList" fileName="#{msg.pessoa}"/>
				</h:commandLink><rich:spacer width="10px"/>

				<h:outputText value="#{msg.exportarDadosPagina}" style="font-weight:bold"/>:
				<h:commandLink>
					<p:graphicImage value="/images/excel.png" style="border:0;"/>
					<p:dataExporter type="xls" target="pessoaList" fileName="#{msg.pessoa}" />
				</h:commandLink>
				<h:commandLink>
					<p:graphicImage value="/images/pdf.png" style="border:0;"/>
					<p:dataExporter type="pdf" target="pessoaList" fileName="#{msg.pessoa}"/>
				</h:commandLink>
			</p:panel>
		</h:form>
	</div>
</ui:composition>